Calendar with CouchDB

2011-10-25

Seems like I'll be heading to the OpenRheinRuhr this year, I just won a ticket for it!

Countdown to OpenRheinRuhr

I'd like to write a little bit about CouchDB, and how you can use it with Makura, in order to find better ways to model the next version of this library.

This is a little preview of what we're going to be dealing with tomorrow:

require 'makura'

Makura::Model.database = 'coulendar'

class Event
  include Makura::Model

  properties :from, :to, :desc

  def from=(time)
    self['from'] = time.to_i
  end

  def from
    Time.at(self['from'].to_i)
  end

  def to=(time)
    self['to'] = time.to_i
  end

  def to
    Time.at(self['to'].to_i)
  end
end

require 'bacon'
Bacon.summary_on_exit

describe Event do
  before do
    Event.database = 'coulendar-test'
    Event.database.destroy! # clean up
    Event.database = 'coulendar-test'
  end

  it 'has a description' do
    desc = 'Writing blog post'
    from = Time.local(2011, 10, 25, 23)
    to = Time.local(2011, 10, 25, 24)

    event = Event.new(from: from, to: to, desc: desc)
    event.save

    event.desc.should == 'Writing blog post'
    event.from.hour.should == 23
  end
end